import java.io.Serializable;
import java.util.Random;

/**
 * represents the Pub where Player objects visit to cash in on unused time in the Turn
 * located inside of the Town
 * @author Megan Beebe
 *
 */
public class Pub implements Serializable {
	/**
	 * Awards the player an amount of money for gambling.
	 * Based off the algorithm: Money Bonus = Round Bonus * random between 0 and Time Bonus
	 * Does not update the main screen yet, but you can see it works by the print statement.
	 * 
	 * @param p the player visiting the pub
	 */
	
	public int pubMoney(Player p) {
		Random rand = new Random();
		int moneyBonus = 0;
		int roundBonus = 0;
		int timeBonus = 0;
		if ((GameModel.getInstance().getRound()).getRoundNum() == 1 || (GameModel.getInstance().getRound()).getRoundNum() == 2 
				|| (GameModel.getInstance().getRound()).getRoundNum() == 3)
			roundBonus = 50;
		else if ((GameModel.getInstance().getRound()).getRoundNum() == 4 || (GameModel.getInstance().getRound()).getRoundNum() == 5
				|| (GameModel.getInstance().getRound()).getRoundNum() == 6 || (GameModel.getInstance().getRound()).getRoundNum() == 7)
			roundBonus = 100;
		else if ((GameModel.getInstance().getRound()).getRoundNum() == 12)
			roundBonus = 200;
		else
			roundBonus = 150;
		
		//get time bonus
		int time = (GameModel.getInstance().getTurn().getT()).getTimeLeft();
		if (time > 0 && time <= 12)
			timeBonus = 50;
		else if (time > 12 && time <= 25)
			timeBonus = 100;
		else if (time > 25 && time <= 37)
			timeBonus = 150;
		else
			timeBonus = 200;
		
		moneyBonus = roundBonus + rand.nextInt(timeBonus);
		
		if (moneyBonus > 250)
			moneyBonus = 250;
		
		p.setMoney(p.getMoney()+moneyBonus);

		GameModel.getInstance().getTurn().getT().setPubVisited(true);

		
		
		return moneyBonus;
	}

}
